/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stateless;

import entity.Users;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author antonio
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class StatelessSessionLoginBean implements StatelessSessionLoginBeanLocal {
    
    @PersistenceContext(unitName = "SampleApplication-ejbPU")
    EntityManager manager;

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Users login(String username, String password) {
        Users u = manager.find(Users.class, username);
        if(u != null && u.getPassword().equals(password)) {
            return u;
        }
        return null;
    }

}
